<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>菜鸟教程</title>
  </head>
  <body>
    <script type="text/javascript">
      const result = [1, 2, 3].toString();
      console.log(result);

      const result2 = String([1, 3, 5]);
      console.log(result2);

      const arr = ["a", "b", "c"];
      const result3 = arr.join();
      console.log(result3);

      const result4 = arr.join("-");
      console.log(result4);

      console.log(typeof arr);
      console.log("arr=" + JSON.stringify(arr));

      console.log("将伪数组转换为真数组：");
      const name = "helloworld";
      console.log(Array.from(name));

      console.log("创建数组");
      const arr2 = Array.of(1, "abc", true);
      console.log(arr2);

      console.log("数组元素的添加和删除：");
      console.log("添加数组元素");
      var arr3 = ["张三", "李四", "王五"];
      var result5 = arr3.push("马六");
      console.log(arr3);

      var result6 = arr3.push("赵七", "刘八");
      console.log(arr3);

      console.log("删除数组元素");
      var array = ["张三1", "张三2", "张三3"];
      var result7 = array.pop();
      console.log(array);

      console.log("在数组最前面添加元素：");
      var result8 = array.unshift("李四");
      console.log(array);

      var result9 = array.unshift("李五", "李六");
      console.log(array);

      console.log("删除数组第一个元素：");
      console.log("删除前数组元素为：" + array);
      var result10 = array.shift();
      console.log("删除后数组元素为：" + array);

      console.log(
        "splice()：从数组中删除指定的一个或多个元素，返回结果为被删除元素组成的新数组（会改变原来的数组）。备注：该方法会改变原数组，会将指定元素从原数组中删除；被删除的元素会封装到一个新的数组中返回。"
      );
      var arr1 = ["a", "b", "c", "d", "e", "f"];
      var result11 = arr1.splice(1);
      console.log(arr1);
      console.log(result11);

      console.log("删除数组最后两个元素");
      var arr3 = ["a", "b", "c", "d", "e", "f"];
      var result12 = arr3.splice(-2);
      console.log(arr3);
      console.log(result12);
    </script>
  </body>
</html>
